package com.jiayuge.server.config.exception;

import com.jiayuge.server.common.entity.RespBean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;
import java.sql.SQLNonTransientException;

/**
 * 功能: 全局异常处理
 *
 * @Program: yeb
 * @Date: 2021-11-22 14:37
 * @Author Jiayu.Yang
 */
@RestControllerAdvice
public class GlobalException {

    //自定义异常拦截响应
//    @ExceptionHandler(SQLException.class)
    public RespBean mySqlException(SQLException e){
        if (e instanceof SQLIntegrityConstraintViolationException) {
            return RespBean.error("该数据有关联数据，操作失败");
        }
        return RespBean.error("数据库异常，操作失败");
    }
}
